package Frame.shopSet;

import FCRendering.FCRBattleOrderConstant;
import FCRendering.FCRMaster;
import FCRendering.sw.FCRValues;
import Frame.entity.UnifyShopSayUIEntity;
import Function.FCMutilPlayCache;
import VWorldGameStudio.FCPlayerInfo;
import VWorldGameStudio.FCRPlayerLink;
import socket.FCRSocketClient;
import socket.FCRSocketServer;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Vector;

import static FCRendering.FCRMaster.*;

//对话本地的队友
public class FunctionTalkToParnerShop extends AShopFuntion {

    boolean isNpcInTeam = false;
    String[] talks = new String[]{"有什么想法吗？说出来便是","你不会想让我走吧？？？好难过","？？？","今天的天气不错"
            ,"？？？？？","终于想起我了吗","恭喜你发现了能和我对话的功能","其实你可以找别的小伙伴入队","什么事？"};
    String[] talks2 = new String[]{"终于想起我了吗？？","等你很久了，这里蚊子很多呢",".......","让我升升级呗","什么事？"};
    FCPlayerInfo p;
    public FunctionTalkToParnerShop(FCPlayerInfo playerInfo) {
         p = playerInfo;
        buildShopWindow();
    }

    public void buildShopWindow() {
        for (FCRPlayerLink link : FCMutilPlayCache.getTeamMembers()) {
            if(p.getName().equals(link.curPlayerName) && p.getAliasUID().equals(link.curPlayerHostUID)){
                isNpcInTeam = true;
            }
        }
        resetUI();
    }

    private void resetUI() {
        FCRValues.resetUnifySayUIEntity();
        Random random = new Random();
        FCRValues.leftWindowUI[0].leftText = p.getChName()+":";

        if(isNpcInTeam){
            FCRValues.leftWindowUI[1].rightText = talks[Math.min(random.nextInt(talks.length), talks.length-1)];
            FCRValues.rightWindowUI[5].rightText = "脱离留在原地";
        }else {
            FCRValues.leftWindowUI[1].rightText = talks2[Math.min(random.nextInt(talks2.length), talks2.length-1)];
            FCRValues.rightWindowUI[5].rightText = "来进队";
        }

        FCRValues.rightWindowUI[6].rightText = "没事";
    }

    @Override
    public void clickLeftWindow(int i, UnifyShopSayUIEntity entity) {

    }


    @Override
    public void clickRightWindow(int i, UnifyShopSayUIEntity entity) {
        switch (i) {
            case 5:
                if(isNpcInTeam){
                    gameSave.getOutTeamLocalNpcs().put(p.getName(), p);
                    player1.quitTeam(p);
                    fcv.getMessage().add(p.getChName()+" 脱离了队伍");
                    fcv.showMessage();
                    fcv.setOpenSayShop(false);
                    FCRMaster.fcv.setOpenSay(false);
                    FCRMaster.fcv.setSayNpcName(null);
                    FCRMaster.fcv.setSayNpcTextNum(0);
                }else {
                    if(!player1.joinInTeam(p)){
                        fcv.getMessage().add(p.getChName()+" 无法加入队伍，队伍满了");
                        fcv.showMessage();
                    }else {
                        fcv.getMessage().add(p.getChName()+" 加入了队伍");
                        fcv.showMessage();
                    }
                    fcv.setOpenSayShop(false);
                    FCRMaster.fcv.setOpenSay(false);
                    FCRMaster.fcv.setSayNpcName(null);
                    FCRMaster.fcv.setSayNpcTextNum(0);
                }
                break;
            case 6:
                fcv.setOpenSayShop(false);
                FCRMaster.fcv.setOpenSay(false);
                FCRMaster.fcv.setSayNpcName(null);
                FCRMaster.fcv.setSayNpcTextNum(0);
                break;
        }
    }
}
